from django.shortcuts import render, redirect, get_object_or_404
from .models import Comment
from blog.models import Post


# Create your views here.


def add_comment(request, post_id):
    name = request.POST.get("name")
    email = request.POST.get("email")
    text = request.POST.get("text")
    comment = Comment(name=name, email=email, text=text, post_id=post_id)
    Comment.save(comment)
    post = get_object_or_404(Post, pk=post_id)
    return redirect(post)
